﻿using System;
using ApiScanner.Core;
using InfiniTec;

namespace ApiScannerShell.ViewModels
{
    public sealed class FileSystemScannerTestConfigurationElementViewModel : TestConfigurationElementViewModel<FileSystemScannerTestConfigurationElementViewModel, FileSystemScannerTestConfigurationElement>
    {
        private FileSystemScannerModuleConfigurationElementCollectionViewModelCollection _Modules;

        public FileSystemScannerModuleConfigurationElementCollectionViewModelCollection Modules
        {
            get { return GetChildViewModel(v => v.Modules); }
        }

        public string RootDirectory
        {
            get { return GetValue(v => v.RootDirectory); }
            set { SetValue(v => v.RootDirectory, value); }
        }

        public FileSystemScannerTestConfigurationElementViewModel(FileSystemScannerTestConfigurationElement element, Action<IViewModel<TestConfigurationElement>> removeAction) : base(element, removeAction)
        {
            AddSimpleMapping(v => v.RootDirectory, () => RootDirectory.IsNullOrEmpty() ? "The root directory must be specified.": null);
            
            LoadValuesFromModel();
        }

        public override string DisplayName
        {
            get { return "Filesystem scanner"; }
        }

        public override string Description
        {
            get { return "Scans the local computer for applications which have a dependency on MAPI, CDOEX and similar APIs."; }
        }

        protected override void ModelChanged()
        {
            _Modules = new FileSystemScannerModuleConfigurationElementCollectionViewModelCollection(Model.Modules);
            RegisterChildViewModel(v => v.Modules, _Modules);

        }
    }
}